package com.phantasy.scene.sceneUnit.baseUnit
{
	import com.phantasy.proto.p_skin;
	import com.phantasy.scene.sceneUnit.IMutualUnit;
	import com.phantasy.scene.sceneUnit.baseUnit.things.avatar.Avatar;
	import com.phantasy.scene.sceneUnit.baseUnit.things.avatar.AvatarConstant;
	import com.phantasy.scene.sceneUnit.baseUnit.things.heartbeat.ThingFrameFrequency;
	import com.phantasy.scene.sceneUtils.Slice;
	import com.phantasy.scene.tile.Pt;
	
	import flash.display.Sprite;
	import flash.events.DataEvent;
	import flash.geom.Point;

	/**
	 *通用化身 
	 * @author liseen
	 * 
	 */	
	public class MutualAvatar extends Sprite implements IMutualUnit
	{
		public var onlyKey:String;//唯一标识
		public var isDead:Boolean;//是否死亡
		public var id:Number;//角色id
		public var dir:int = 4;
		
		private var _hideAvatar:Boolean;
		protected var buffs:Array;
		protected var avatar:Avatar;//化身
		protected var skinData:p_skin;//皮肤数据
		
		public function MutualAvatar()
		{
			buffs=[];
			this.onlyKey = OnlyIDCreater.createID();
		}
		/**
		 *隐藏（其实就是从显示列表中删除此对象） 
		 * 
		 */		
		public function hide():void
		{
			if (this.parent)
			{
				this.parent.removeChild(this);
			}
		}
		
		/**
		 *初始化皮肤 
		 * @param skin
		 * @param category
		 * @param sex
		 * 
		 */		
		public function initSkin(skin:p_skin,category:int,sex:int):void
		{
			skinData = skin;
			avatar = new Avatar();
			this.avatar.addEventListener(Avatar.BODY_COMPLETE, this.onBodyComplete);
			this.avatar.initSkin(skin, category, sex);
			this.avatar.mouseChildren = false;
			this.avatar.mouseEnabled = false;
			addChild(this.avatar);
		}
		
		
		protected function onBodyComplete(event:DataEvent):void
		{
			this.avatar.removeEventListener(Avatar.BODY_COMPLETE, this.onBodyComplete);
		}
		
		public function die():void
		{
//			var _local3:Effect;
//			this.play(AvatarConstant.ACTION_DIE, this.dir, ThingFrameFrequency.DIE);
//			var _local1:int = this.numChildren;
//			var _local2:int;
//			while (_local2 < _local1)
//			{
//				_local3 = (this.getChildAt(_local2) as Effect);
//				if (_local3)
//				{
//					_local3.complete();
//				};
//				_local2++;
//			};
		}
		
		public function turnDir(_arg1:int=4):void
		{
			this.dir = _arg1;
			this.play(AvatarConstant.ACTION_STAND, this.dir, ThingFrameFrequency.STAND);
		}
		
		public function play(_arg1:String, _arg2:int, _arg3:int):void
		{
			if (((!((this.avatar == null))) && (((((!((_arg1 == this.avatar.selectState))) || (!((_arg2 == this.avatar.selectDir))))) || (!((_arg3 == this.avatar.selectSpeed)))))))
			{
				this.avatar.play(_arg1, _arg2, _arg3, this._hideAvatar);
			}
		}
		
		public function get slice():Point
		{
			var _local1:int = int(((this.x - Slice.offsetx) / Slice.width));
			var _local2:int = int(((this.y - Slice.offsety) / Slice.height));
			var _local3:Point = new Point(_local1, _local2);
			return (_local3);
		}

		
		public function set sceneType(_arg1:int):void
		{
		}
		
		public function get sceneType():int
		{
			return 0;
		}
		
		public function get unitKey():String
		{
			return null;
		}
		
		public function get index():Pt
		{
			return null;
		}
		
		public function mouseOver():void
		{
		}
		
		public function mouseOut():void
		{
		}
		
		public function mouseDown():void
		{
		}
		
		public function remove():void
		{
		}
	}
}